/*
 * Пакет Интерфейс пользователя
 */
package vitarium.gui;

import java.awt.Image;

import java.net.URL;
import javax.swing.ImageIcon;

/** Vitarium GUI */
public class VitaUI extends javax.swing.JFrame {

    /** Создает VitaUI */
    public VitaUI() {
        super("Vitarium");
        initComponents();
        setIconImage(getIcon());

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        viViewPanel = new javax.swing.JScrollPane();
        viToolBar = new javax.swing.JToolBar();
        viButtonPauseEcoing = new javax.swing.JButton();
        viButtonStartEcoing = new javax.swing.JButton();
        viButtonNext = new javax.swing.JButton();
        viMenuBar = new javax.swing.JMenuBar();
        viMenuFile = new javax.swing.JMenu();
        viMenuFileCreate = new javax.swing.JMenuItem();
        viMenuFileLoad = new javax.swing.JMenuItem();
        viMenuFileSave = new javax.swing.JMenuItem();
        viMenuFileReset = new javax.swing.JMenuItem();
        viMenuFileSeparator = new javax.swing.JPopupMenu.Separator();
        viMenuFileExit = new javax.swing.JMenuItem();
        viMenuEdit = new javax.swing.JMenu();
        viMenuEditRun = new javax.swing.JMenuItem();
        viMenuEditPause = new javax.swing.JMenuItem();
        viMenuEditNext = new javax.swing.JMenuItem();
        viSeparatorMenuEdit = new javax.swing.JPopupMenu.Separator();
        viMenuEditSettings = new javax.swing.JMenuItem();
        viMenuHelp = new javax.swing.JMenu();
        viMenuHelpManual = new javax.swing.JMenuItem();
        viSeparator1 = new javax.swing.JPopupMenu.Separator();
        viMenuHelpAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        viToolBar.setRollover(true);

        viButtonPauseEcoing.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/pause-toolbar.png"))); // NOI18N
        viButtonPauseEcoing.setFocusable(false);
        viButtonPauseEcoing.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        viButtonPauseEcoing.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        viButtonPauseEcoing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viButtonPauseEcoingActionPerformed(evt);
            }
        });
        viToolBar.add(viButtonPauseEcoing);

        viButtonStartEcoing.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/run-toolbar.png"))); // NOI18N
        viButtonStartEcoing.setFocusable(false);
        viButtonStartEcoing.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        viButtonStartEcoing.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        viButtonStartEcoing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viButtonStartEcoingActionPerformed(evt);
            }
        });
        viToolBar.add(viButtonStartEcoing);

        viButtonNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/next-toolbar.png"))); // NOI18N
        viButtonNext.setFocusable(false);
        viButtonNext.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        viButtonNext.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        viButtonNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viButtonNextActionPerformed(evt);
            }
        });
        viToolBar.add(viButtonNext);

        viMenuFile.setText("Файл");

        viMenuFileCreate.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        viMenuFileCreate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/new.png"))); // NOI18N
        viMenuFileCreate.setText("Создать");
        viMenuFile.add(viMenuFileCreate);

        viMenuFileLoad.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        viMenuFileLoad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/open.png"))); // NOI18N
        viMenuFileLoad.setText("Загрузить");
        viMenuFileLoad.setEnabled(false);
        viMenuFile.add(viMenuFileLoad);

        viMenuFileSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        viMenuFileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/save.png"))); // NOI18N
        viMenuFileSave.setText("Сохранить");
        viMenuFileSave.setEnabled(false);
        viMenuFile.add(viMenuFileSave);

        viMenuFileReset.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        viMenuFileReset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/revert.png"))); // NOI18N
        viMenuFileReset.setText("Сбросить");
        viMenuFile.add(viMenuFileReset);
        viMenuFile.add(viMenuFileSeparator);

        viMenuFileExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        viMenuFileExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/exit.png"))); // NOI18N
        viMenuFileExit.setText("Выход");
        viMenuFileExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viMenuFileExitActionPerformed(evt);
            }
        });
        viMenuFile.add(viMenuFileExit);

        viMenuBar.add(viMenuFile);

        viMenuEdit.setText("Правка");

        viMenuEditRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/run.png"))); // NOI18N
        viMenuEditRun.setText("Запуск");
        viMenuEditRun.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viMenuEditRunActionPerformed(evt);
            }
        });
        viMenuEdit.add(viMenuEditRun);

        viMenuEditPause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/pause.png"))); // NOI18N
        viMenuEditPause.setText("Пауза");
        viMenuEditPause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viMenuEditPauseActionPerformed(evt);
            }
        });
        viMenuEdit.add(viMenuEditPause);

        viMenuEditNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/next.png"))); // NOI18N
        viMenuEditNext.setText("Следующий ход");
        viMenuEditNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viMenuEditNextActionPerformed(evt);
            }
        });
        viMenuEdit.add(viMenuEditNext);
        viMenuEdit.add(viSeparatorMenuEdit);

        viMenuEditSettings.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/configure.png"))); // NOI18N
        viMenuEditSettings.setText("Настройки");
        viMenuEditSettings.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viMenuEditSettingsActionPerformed(evt);
            }
        });
        viMenuEdit.add(viMenuEditSettings);

        viMenuBar.add(viMenuEdit);

        viMenuHelp.setText("Справка");

        viMenuHelpManual.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        viMenuHelpManual.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/help-contents.png"))); // NOI18N
        viMenuHelpManual.setText("Содержание");
        viMenuHelpManual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viMenuHelpManualActionPerformed(evt);
            }
        });
        viMenuHelp.add(viMenuHelpManual);
        viMenuHelp.add(viSeparator1);

        viMenuHelpAbout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vitarium/resources/icons/help-about.png"))); // NOI18N
        viMenuHelpAbout.setText("О программе");
        viMenuHelpAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viMenuHelpAboutActionPerformed(evt);
            }
        });
        viMenuHelp.add(viMenuHelpAbout);

        viMenuBar.add(viMenuHelp);

        setJMenuBar(viMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(viToolBar, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(viViewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                .addGap(12, 12, 12))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(viToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(viViewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void viMenuFileExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viMenuFileExitActionPerformed

        viMapPanel.pause();
        ViExitDialog viExitDialog = new ViExitDialog(this, true);
        viExitDialog.setVisible(true);
        if (viExitDialog.getReturnStatus() == 1) {
            System.exit(0);
        }
    }//GEN-LAST:event_viMenuFileExitActionPerformed

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        viMapPanel.changeCurrentLocation(evt);
    }//GEN-LAST:event_formKeyPressed

    private void viButtonStartEcoingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viButtonStartEcoingActionPerformed
        viMapPanel.start();
    }//GEN-LAST:event_viButtonStartEcoingActionPerformed

    private void viButtonPauseEcoingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viButtonPauseEcoingActionPerformed
        viMapPanel.pause();
    }//GEN-LAST:event_viButtonPauseEcoingActionPerformed

    private void viMenuEditRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viMenuEditRunActionPerformed
        viMapPanel.start();
    }//GEN-LAST:event_viMenuEditRunActionPerformed

    private void viMenuEditPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viMenuEditPauseActionPerformed
        viMapPanel.pause();
}//GEN-LAST:event_viMenuEditPauseActionPerformed

    private void viButtonNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viButtonNextActionPerformed
        viMapPanel.next();
    }//GEN-LAST:event_viButtonNextActionPerformed

    private void viMenuEditNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viMenuEditNextActionPerformed
        viMapPanel.next();
    }//GEN-LAST:event_viMenuEditNextActionPerformed

    private void viMenuHelpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viMenuHelpAboutActionPerformed
        viMapPanel.pause();
        ViAboutDialog about = new ViAboutDialog(this, true);
        about.setVisible(true);
    }//GEN-LAST:event_viMenuHelpAboutActionPerformed

    private void viMenuHelpManualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viMenuHelpManualActionPerformed
        viMapPanel.pause();
        ViHelpDialog help = new ViHelpDialog(this, true);
        help.setVisible(true);
    }//GEN-LAST:event_viMenuHelpManualActionPerformed

    private void viMenuEditSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viMenuEditSettingsActionPerformed
        viMapPanel.pause();
        ViSettingsDialog settings = new ViSettingsDialog(this, true, viMapPanel);
        settings.setVisible(true);
    }//GEN-LAST:event_viMenuEditSettingsActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton viButtonNext;
    private javax.swing.JButton viButtonPauseEcoing;
    private javax.swing.JButton viButtonStartEcoing;
    private javax.swing.JMenuBar viMenuBar;
    private javax.swing.JMenu viMenuEdit;
    private javax.swing.JMenuItem viMenuEditNext;
    private javax.swing.JMenuItem viMenuEditPause;
    private javax.swing.JMenuItem viMenuEditRun;
    private javax.swing.JMenuItem viMenuEditSettings;
    private javax.swing.JMenu viMenuFile;
    private javax.swing.JMenuItem viMenuFileCreate;
    private javax.swing.JMenuItem viMenuFileExit;
    private javax.swing.JMenuItem viMenuFileLoad;
    private javax.swing.JMenuItem viMenuFileReset;
    private javax.swing.JMenuItem viMenuFileSave;
    private javax.swing.JPopupMenu.Separator viMenuFileSeparator;
    private javax.swing.JMenu viMenuHelp;
    private javax.swing.JMenuItem viMenuHelpAbout;
    private javax.swing.JMenuItem viMenuHelpManual;
    private javax.swing.JPopupMenu.Separator viSeparator1;
    private javax.swing.JPopupMenu.Separator viSeparatorMenuEdit;
    private javax.swing.JToolBar viToolBar;
    protected javax.swing.JScrollPane viViewPanel;
    // End of variables declaration//GEN-END:variables
    protected VitaMap viMapPanel;

    protected Image getIcon() {
        URL imgURL = this.getClass().getResource("/vitarium/resources/appicon/vitaicon.png");
        if (imgURL != null) {
            return new ImageIcon(imgURL).getImage();
        } else {
            return null;
        }
    }
}
